﻿ package swing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;

import org.apache.ibatis.session.SqlSession;

import util.AbnormalPopUp;
import util.GetArray;
import util.GetSqlSession;
import util.ICallback;
import util.MyButtonRender;
import util.Mytable;
import util.SelfStarting;
import util.TimerFrame;
import auto.main.Clock;
import auto.main.Test;
import auto.vpn.Vpn;
import baseDao.LogDao;
import baseDao.RecordDao;
import baseDao.TaskListDao;
import baseDao.UserDao;
import entity.Log;
import entity.Record;
import entity.RecordExtend;
import entity.TaskList;
import entity.User;

public class Index extends JFrame {
	/**
	 * 菜单栏、工具栏
	 */
	/*
	 * private static final int JFRAME_WIDTH = 1600; private static final int
	 * JFRAME_HEIGHT=800;
	 */
	private Font font = new Font("微软雅黑", Font.PLAIN, 13);
	
	// zzzzzzzz
	public static User user = Login.getUser();
	public  static Mytable table;//表格
	public static JTextPane textArea;//日志文本域
	//开始按钮
	public static JButton SatrtMission ;
	public static JFrame jFrame ;
	public static List<Integer> list;
	public static JRadioButton s3;
	public static JRadioButton s2;
	public static JRadioButton s1;
	public static JRadioButton s6;
	/*public static void startTo(){
		// 查询任务表中的所有任务
		SqlSession session = GetSqlSession.getSession();
		TaskListDao dao = session.getMapper(TaskListDao.class);
		List<TaskList> all = dao.selectnonExecution(user.getId());
		// 加载到任务列表
		
			Test.exit=true;
			Test.startAuto(all, s3,s2,s1,s6,SatrtMission,list);
			//Clock.connect();
	}*/
	
	
	
	public Index() {
		SqlSession session = GetSqlSession.getSession();
		TaskListDao dao = session.getMapper(TaskListDao.class);
		List<TaskList> all = dao.selectnonExecution(user.getId());
		// 窗口-顶层面板
		jFrame = new JFrame("菜单工具栏");
		Toolkit toolkit = getToolkit();// 获得窗体工具包
		Dimension screenSize = toolkit.getScreenSize();// 获取屏幕大小
		int width = (int) (screenSize.width * 0.8);// 计算窗体新宽度
		int height = (int) (screenSize.height * 0.75);// 计算窗体新宽度

		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setSize(width, height);
		jFrame.setFont(font);
		// 窗口内加入面板
		JPanel jPanel = new JPanel();
		jFrame.setContentPane(jPanel);
		jPanel.setFont(font);
		
		jFrame.addWindowListener(new WindowAdapter() {
			   public void windowClosing(WindowEvent e) {
			    	SqlSession session = GetSqlSession.getSession();
					// 获取user接口:
					UserDao userDao = session.getMapper(UserDao.class);
					// user构造器
					User u = new User(user.getId(), null, null, null, 0, null,null,"true");
					userDao.updateUserFlag(u);
					GetSqlSession.closeSession(session);
					System.exit(0);  //关闭
			   } 
		});
		
		

		BorderLayout lay = new BorderLayout();// 创建一个布局管理器对象，将中间容器设置为此布局管理
		jFrame.setLayout(lay);

		// 面板里面添加子面板--左
		JPanel leftPenel = new JPanel();
		leftPenel.setBorder(BorderFactory.createEtchedBorder());
		leftPenel.setPreferredSize(new Dimension(230, 750));
		leftPenel.setLayout(null);
		jPanel.add(leftPenel, "West");
		leftPenel.setFont(font);

		// zzzzzzzz
		JLabel account = new JLabel("账户：" + user.getUsername());
		account.setBounds(5, 5, 200, 20);
		account.setFont(font);
		leftPenel.add(account);
		// zzzzzzzz
		JLabel integral = new JLabel("将于"+new Date(user.getExpireTime()).toLocaleString()+"过期");
		integral.setBounds(5, 30, 290, 20);
		integral.setFont(font);
		leftPenel.add(integral);

		// 左面板里面的浏览器面板
		JPanel browserPenel = new JPanel();
		browserPenel.setBorder(BorderFactory.createTitledBorder("选择浏览器"));
		// browserPenel.setPreferredSize(new Dimension(220, 120));
		browserPenel.setBounds(5, 55, 220, 125);
		browserPenel.setFont(font);
		leftPenel.add(browserPenel);

		// 单选框
		ButtonGroup g = new ButtonGroup();
		 s1 = new JRadioButton("谷歌");
		s1.setFont(font);
		browserPenel.add(s1);

		 s2 = new JRadioButton("火狐");
		s2.setFont(font);
		browserPenel.add(s2);

	 s3 = new JRadioButton("IE");
		s3.setFont(font);
		browserPenel.add(s3);

		/*
		 * JRadioButton s4=new JRadioButton("QQ浏览器"); s4.setFont(font);
		 * browserPenel.add(s4);
		 */

		/*
		 * JRadioButton s5=new JRadioButton("360浏览器"); s5.setFont(font);
		 * browserPenel.add(s5);
		 */

		 s6 = new JRadioButton("随机浏览器", true);
		s6.setFont(font);
		browserPenel.add(s6);
		g.add(s1);
		g.add(s2);
		g.add(s3);
		// g.add(s4);
		// g.add(s5);
		g.add(s6);
		SqlSession session1 = GetSqlSession.getSession();
		// 获取user接口:
		UserDao userDao1 = session.getMapper(UserDao.class);
		User us= userDao1.selectById();
		session1.close();
		// 复选框
		JCheckBox cbOne = new JCheckBox("开启挂机模式	",Boolean.parseBoolean(us.isCheck()));
		cbOne.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println(Boolean.parseBoolean(us.isCheck()));
				SqlSession session = GetSqlSession.getSession();
				// 获取接口:
				UserDao userDao = session.getMapper(UserDao.class);
				String name="";
				if(cbOne.isSelected()){
					name="true";
				}else{
					name="false";
				}
				User u=new User(null,user.getUsername(), null, null,  null,  null, "false",name);
				try {
					SelfStarting.changeStart(cbOne.isSelected());
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				userDao.updateUserIsCheck(u);
				session.close();
			}
		});
		cbOne.setBounds(60, 185, 120, 20);
		cbOne.setFont(font);
		leftPenel.add(cbOne);

		// 结束任务按钮
		JButton  endTask= new JButton("结束任务");
		endTask.setBounds(120, 245, 100, 25);
		
		endTask.setFont(font);
		endTask.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					SatrtMission.setEnabled(true);
					SatrtMission.setText("开始任务");
					Test.exit=false;
					Test.cls();
					
					Test.clsta(SatrtMission);
				}
			}
		});
		leftPenel.add(endTask);

		// 任务刷新按钮
		JButton refurbishTask = new JButton("任务刷新");
		refurbishTask.setBounds(15, 245, 100, 25);
		refurbishTask.setFont(font);
		refurbishTask.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					
					
					Index.refresh(table, user.getId());
				}
			}
		});
		leftPenel.add(refurbishTask);

		// 查看热词按钮
		JButton refurbishIntegral = new JButton("查看热词");
		refurbishIntegral.setBounds(120, 305, 100, 25);
		refurbishIntegral.setFont(font);
		refurbishIntegral.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				OutputStreamWriter output = null;
				// 查询任务表中的所有任务
				SqlSession session = GetSqlSession.getSession();
				RecordDao dao = session.getMapper(RecordDao.class);
				List<Record> all = dao.selectByTime();
				session.close();
				//String webUrl;//网址
				// String time; //时间
				// String word; //词
				System.out.println(all.size()+"Record");
				StringBuffer sb = new StringBuffer(); // 原有txt内容
				try {
					sb.append("生成时间  \t\t\t\t\t  网址 \t\t\t\t  广告词\r\n");
					for (int i = 0; i < all.size(); i++) {
						
						// 循环拼词库
						sb.append(new Date(Long.parseLong(all.get(i).getTime())).toLocaleString()+"\t\t"+all.get(i).getWebUrl()+"\t\t"+all.get(i).getWord() + "\r\n");
					}
					File file = new File(System.getProperty("user.dir")
							+ "\\notepad\\record.txt");
					if (!file.exists()) {// 没有文件
						//JOptionPane.showMessageDialog(null, "文件被非法删除,请使用数据\n库添加或重新安装软件");
						AbnormalPopUp apu=new AbnormalPopUp();
						apu.setIc(new ICallback() {
							@Override
							public void postExec() {
								jFrame.dispose();
								Index.jFrame.dispose();
							}
						}, "缺少程序依赖文件,请重新安装程序");
						return;
					} 
						output = new OutputStreamWriter(
								new FileOutputStream(file), "UTF-8");
						// 写入lex.txt
						output.write(sb.toString());
						output.close();
						// 获得当前工程路径,打开指定txt文件
						Vpn.executeCmd("notepad " + System.getProperty("user.dir")+"\\notepad\\record.txt");
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				
			}
		});
		leftPenel.add(refurbishIntegral);

		// 删已执行按钮
		JButton deleteExecute = new JButton("删已执行");
		deleteExecute.setBounds(15, 275, 100, 25);
		deleteExecute.setFont(font);
		deleteExecute.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					SqlSession session = GetSqlSession.getSession();
					// 获取接口:
					TaskListDao taskListDao = session.getMapper(TaskListDao.class);
					// 删除已执行
					int a = taskListDao.deleteByYes(user.getId());
					session.commit();
					GetSqlSession.closeSession(session);
					Index.refresh(table, user.getId());
				}
			}
		});
		leftPenel.add(deleteExecute);

		// 删未执行按钮
		JButton deleteNotExecute = new JButton("删未执行");
		deleteNotExecute.setBounds(120, 275, 100, 25);
		deleteNotExecute.setFont(font);
		deleteNotExecute.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					SqlSession session = GetSqlSession.getSession();
					// 获取接口:
					TaskListDao taskListDao = session.getMapper(TaskListDao.class);
					// 删除未执行
					System.out.println(user.getId());
					int a = taskListDao.deleteByNo(user.getId());
					System.out.println(a);
					GetSqlSession.closeSession(session);
					Index.refresh(table, user.getId());
				}
			}
		});
		leftPenel.add(deleteNotExecute);

		// 删除异常按钮
		JButton deleteAbnormal = new JButton("删除异常");
		deleteAbnormal.setBounds(15, 305, 100, 25);
		deleteAbnormal.setFont(font);
		deleteAbnormal.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					SqlSession session = GetSqlSession.getSession();
					// 获取接口:
					TaskListDao taskListDao = session.getMapper(TaskListDao.class);
					// 删除异常
					int a = taskListDao.deleteByYC(user.getId());
					session.commit();
					GetSqlSession.closeSession(session);
					Index.refresh(table, user.getId());
				}
			}
		});
		leftPenel.add(deleteAbnormal);

		// 任务计划按钮
		JButton taskPlanning = new JButton("任务计划");
		taskPlanning.setBounds(15, 210, 100, 25);
		taskPlanning.setFont(font);
		taskPlanning.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					TackTo text = new TackTo(Index.this);
					text.setVisible(true);
				}
			}
		});
		leftPenel.add(taskPlanning);

		
		
		
		// ID文本框
		JTextField idText = new JTextField(10);
		idText.setBounds(120, 336, 90, 23);
		leftPenel.add(idText);
		
		// 删指定ID
		JButton deleteId = new JButton("删指定ID");
		deleteId.setBounds(15, 335, 100, 25);
		deleteId.setFont(font);
		deleteId.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					SqlSession session = GetSqlSession.getSession();
					// 获取接口:
					TaskListDao taskListDao = session.getMapper(TaskListDao.class);
					// 删指定ID
					if(!"".equals(idText.getText())) {
						TaskList tk=new TaskList();
						tk.setUserId(user.getId());
						System.out.println(GetArray.m.get(Integer.parseInt(idText.getText())));
						tk.setTaskId(GetArray.m.get(Integer.parseInt(idText.getText())));
						int a = taskListDao.deleteById(tk);
						session.commit();
						GetSqlSession.closeSession(session);
						Index.refresh(table, user.getId());
					}
				}
			}
		});
		leftPenel.add(deleteId);
		
		// 网址文本框
		JTextField urlText = new JTextField(10);
		urlText.setBounds(120, 366, 90, 23);
		leftPenel.add(urlText);

		// 删指定网址按钮
		JButton deleteUrl = new JButton("删指定网址");
		deleteUrl.setBounds(15, 365, 100, 25);
		deleteUrl.setFont(font);
		deleteUrl.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if("执行中....".equals(SatrtMission.getText())){
					AbnormalPopUp apu=new AbnormalPopUp();
					apu.setIc(new ICallback() {
						@Override
						public void postExec() {
							SatrtMission.setEnabled(true);
							SatrtMission.setText("开始任务");
							Test.exit=false;
						}
					}, "任务正在执行中，是否停止任务");
				}else{
					SqlSession session = GetSqlSession.getSession();
					// 获取接口:
					TaskListDao taskListDao = session.getMapper(TaskListDao.class);
					// 删指定网址
					if(!"".equals(urlText.getText())) {
						TaskList tk=new TaskList();
						tk.setUserId(user.getId());
						tk.setYourWebsite(urlText.getText());
						int a = taskListDao.deleteByUrl(tk);
						session.commit();
						GetSqlSession.closeSession(session);
						Index.refresh(table, user.getId());
					}
				}
			}
		});
		leftPenel.add(deleteUrl);


		// 异常改未执行按钮
				JButton updateAbnormalAndNotExecute = new JButton("异常任务改为未执行");
				updateAbnormalAndNotExecute.setBounds(15, 395, 160, 25);
				updateAbnormalAndNotExecute.setFont(font);
				updateAbnormalAndNotExecute.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if("执行中....".equals(SatrtMission.getText())){
							AbnormalPopUp apu=new AbnormalPopUp();
							apu.setIc(new ICallback() {
								@Override
								public void postExec() {
									SatrtMission.setEnabled(true);
									SatrtMission.setText("开始任务");
									Test.exit=false;
								}
							}, "任务正在执行中，是否停止任务");
						}else{
							SqlSession session = GetSqlSession.getSession();
							TaskListDao taskDao = session.getMapper(TaskListDao.class);
							TaskList s = new TaskList();
							s.setUserId(user.getId());
							Integer i = taskDao.updateException(s);
							System.out.println("修改有异常为未执行：：" + i);
							session.commit();
							GetSqlSession.closeSession(session);
							Index.refresh(table, user.getId());
						}
					}
				});
				leftPenel.add(updateAbnormalAndNotExecute);

				
				// 不点任务改未执行按钮
				/*JButton updateNotDotAndNotExecute = new JButton("不点任务改为未执行????");
				updateNotDotAndNotExecute.setBounds(15, 425, 160, 25);
				updateNotDotAndNotExecute.setFont(font);
				updateNotDotAndNotExecute.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if("执行中....".equals(SatrtMission.getText())){
							AbnormalPopUp apu=new AbnormalPopUp();
							apu.setIc(new ICallback() {
								@Override
								public void postExec() {
									SatrtMission.setEnabled(true);
									SatrtMission.setText("开始任务");
									Test.exit=false;
								}
							}, "任务正在执行中，是否停止任务");
						}else{
							System.exit(0);  //关闭
						}
					}
				});
				leftPenel.add(updateNotDotAndNotExecute);*/
				
				
				

				// 全部任务改未执行按钮
				JButton updateAllAndNotExecute = new JButton("全部任务改为未执行");
				updateAllAndNotExecute.setBounds(15, 425, 160, 25);
				updateAllAndNotExecute.setFont(font);
				updateAllAndNotExecute.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if("执行中....".equals(SatrtMission.getText())){
							AbnormalPopUp apu=new AbnormalPopUp();
							apu.setIc(new ICallback() {
								@Override
								public void postExec() {
									SatrtMission.setEnabled(true);
									SatrtMission.setText("开始任务");
									Test.exit=false;
								}
							}, "任务正在执行中，是否停止任务");
						}else{
							SqlSession session = GetSqlSession.getSession();
							TaskListDao taskDao = session.getMapper(TaskListDao.class);
	
							TaskList s = new TaskList();
							s.setUserId(user.getId());
	
							Integer i = taskDao.updateNoExecute(s);
							System.out.println("全部任务改未执行：：" + i);
							session.commit();
							GetSqlSession.closeSession(session);
							Index.refresh(table, user.getId());
						}
					}
				});
				leftPenel.add(updateAllAndNotExecute);

				// 全部任务改+1天未执行按钮
				JButton updateAllAndPlusOneNotExecute = new JButton("全部任务改为+1天未执行");
				updateAllAndPlusOneNotExecute.setBounds(15, 455, 185, 25);
				updateAllAndPlusOneNotExecute.setFont(font);
				updateAllAndPlusOneNotExecute.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if("执行中....".equals(SatrtMission.getText())){
							AbnormalPopUp apu=new AbnormalPopUp();
							apu.setIc(new ICallback() {
								@Override
								public void postExec() {
									SatrtMission.setEnabled(true);
									SatrtMission.setText("开始任务");
									Test.exit=false;
								}
							}, "任务正在执行中，是否停止任务");
						}else{
							SqlSession session = GetSqlSession.getSession();
							TaskListDao taskDao = session.getMapper(TaskListDao.class);
							TaskList s = new TaskList();
							s.setUserId(user.getId());
							Integer i = taskDao.updateAddOneDayAndNoExecute(s);
							System.out.println("全部任务改+1天未执行：：" + i);
							session.commit();
							GetSqlSession.closeSession(session);
							Index.refresh(table, user.getId());
						}
					}
				});
				leftPenel.add(updateAllAndPlusOneNotExecute);
				//查看统计数
				JButton selectAll = new JButton("查看统计数");
				selectAll.setBounds(15, 485, 185, 25);
				selectAll.setFont(font);
				selectAll.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						OutputStreamWriter output = null;
						// 查询任务表中的所有任务
						SqlSession session = GetSqlSession.getSession();
						RecordDao dao = session.getMapper(RecordDao.class);
						List<RecordExtend> all = dao.selectByTimeCount(Login.getUser().getId());
						
						
						
						//RecordDao dao = session.getMapper(RecordDao.class);
						//if(Login.getUser().getId())
						
						
						
						session.close();
						//String webUrl;//网址
						// String time; //时间
						// String word; //词
						System.out.println(all.size()+"Record");
						StringBuffer sb = new StringBuffer(); // 原有txt内容
						try {
							sb.append("点击次数  \t\t\t\t  网址 \t\t\t\t  广告词 \t\t状态\r\n");
							for (int i = 0; i < all.size(); i++) {
								
								// 循环拼词库
								sb.append(all.get(i).getCun()+"\t\t\t"+all.get(i).getWebUrl()+"\t\t"+all.get(i).getWord() +"\t\t"+((all.get(i).getState()==1)?"成功":"失败")+ "\r\n");
							}
							File file = new File(System.getProperty("user.dir")
									+ "\\notepad\\recordCount.txt");
							if (!file.exists()) {// 没有文件
								//JOptionPane.showMessageDialog(null, "文件被非法删除,请使用数据\n库添加或重新安装软件");
								AbnormalPopUp apu=new AbnormalPopUp();
								apu.setIc(new ICallback() {
									@Override
									public void postExec() {
										jFrame.dispose();
										Index.jFrame.dispose();
									}
								}, "缺少程序依赖文件,请重新安装程序");
								return;
							} 
								output = new OutputStreamWriter(
										new FileOutputStream(file), "UTF-8");
								// 写入lex.txt
								output.write(sb.toString());
								output.close();
								// 获得当前工程路径,打开指定txt文件
								Vpn.executeCmd("notepad " + System.getProperty("user.dir")+"\\notepad\\recordCount.txt");
						} catch (Exception e1) {
							e1.printStackTrace();
						}
						
					}
				});
				leftPenel.add(selectAll);
		
				
				
		// 面板里面添加子面板--右
		JPanel rightPenel = new JPanel();
		rightPenel.setPreferredSize(new Dimension(1000, 750));
		rightPenel.setBorder(BorderFactory.createEtchedBorder());
		jPanel.add(rightPenel);
		rightPenel.setLayout(null);	
		// 表格
		table= new Mytable();
		//table.setEnabled(false);
		//rightPenel.setPreferredSize(new Dimension(1375, 750));
		Index.refresh(table,user.getId());
		JScrollPane scrollPane1 = new JScrollPane(table);
		//scrollPane1.setPreferredSize(new Dimension(width-320, 750));
		//scrollPane1.setBounds(0, 0,1000, 750);
		scrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		// table.revalidate();
		rightPenel.add(scrollPane1);
		
		table.addMouseListener(new MouseAdapter() { 
			@Override  public void mouseClicked(MouseEvent e) {
				if(table.getSelectedColumn()==8){
					AbnormalPopUp up=new AbnormalPopUp();
					up.setIc(new ICallback() {
						@Override
						public void postExec() {
							SqlSession session = GetSqlSession.getSession();
							// 获取接口:
							TaskListDao taskListDao = session.getMapper(TaskListDao.class);
							TaskList tk=new TaskList();
							tk.setUserId(user.getId());
							tk.setTaskId(GetArray.m.get(table.getSelectedRow()+1));
							int a = taskListDao.deleteById(tk);
							session.commit();
							GetSqlSession.closeSession(session);
							Index.refresh(table, user.getId());
						}
					}, "是否删除？");
				}
			}        
		});
		
		// 日志
		JLabel log = new JLabel("日志：");
		log.setBounds(5, 335, 185, 25);
		log.setFont(font);
		rightPenel.add(log);
		//日志查看
		JButton jb2 = new JButton("查看文件日志");
		
		jb2.setFont(font);
		jb2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				SqlSession session = GetSqlSession.getSession();
				OutputStreamWriter output = null;
				try {
					LogDao dao = session.getMapper(LogDao.class);
					List<Log> list = dao.selectAll();
					session.close();
					System.out.println(list.size()+"wwwwwww");
					StringBuffer sb = new StringBuffer(); // 原有txt内容
					try {
						for (int i = 0; i < list.size(); i++) {
							System.out.println(list.get(i).getStatus()+"昨天");
							String name="";
						  if(list.get(i).getStatus().equals(3)){
							  	name="error";
					        }else if(list.get(i).getStatus().equals(1)){
					        	name="normal";
					        }else if(list.get(i).getStatus().equals(2)){
					        	name="succeed";
					        }
							Date date = new Date(Long.parseLong(list.get(i).getDate()));
						    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
							// 循环拼网址库
							sb.append(date.toLocaleString()+"\t"+name+"\t"+(list.get(i)).getName() + "\r\n");
						}
						File file = new File(System.getProperty("user.dir")
								+ "\\notepad\\Log.log");
						if (!file.exists()) {// 没有文件
							//JOptionPane.showMessageDialog(null, "文件被非法删除,请使用数据\n库添加或重新安装软件");
							AbnormalPopUp apu=new AbnormalPopUp();
							apu.setIc(new ICallback() {
								@Override
								public void postExec() {
									jFrame.dispose();
									Index.jFrame.dispose();
								}
							}, "缺少程序依赖文件,请重新安装程序");
							return;
						} 
							output = new OutputStreamWriter(
									new FileOutputStream(file), "UTF-8");
							// 写入lex.txt
							output.write(sb.toString());
							output.close();
					} catch (Exception e1) {
						e1.printStackTrace();
					}
					/*session = GetSqlSession.getSession();
					dao = session.getMapper(WebsiteDao.class);
					dao.deleteAll();*/
					//session.close();
					// 获得当前工程路径,打开指定txt文件
					Vpn.executeCmd("notepad " + System.getProperty("user.dir")
							+ "\\notepad\\log.log");
					/*File file = new File(System.getProperty("user.dir")
							+ "\\notepad\\webSite.txt");
					String text = main1.txt2String(file);
					String[] split = text.split(System.lineSeparator());*/
					/*Website w = new Website();
					session = GetSqlSession.getSession();
					dao = session.getMapper(WebsiteDao.class);
					for (int i = 0; i < split.length; i++) {
						System.out.println(split[i]);
						w.setWebsite(split[i]);
						dao.add(w);
					}
					session.close();*/
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		rightPenel.add(jb2);
		
		textArea= new JTextPane();// 创建文本域
        JScrollPane scrollPane = new JScrollPane(textArea);
		//scrollPane.setBounds(5, 510,220, height-570);
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		rightPenel.add(scrollPane);
        
		 jFrame.addComponentListener(new ComponentAdapter() {//让窗口响应大小改变事件
	            @Override
	            public void componentResized(ComponentEvent e) {
	            	scrollPane1.setBounds(2,10,rightPenel.getWidth()-2, 300);
	            	scrollPane1.revalidate();
	            	scrollPane.setBounds(2,355,rightPenel.getWidth()-2, rightPenel.getHeight()-355);
	            	scrollPane.revalidate();
	            	jb2.setBounds(rightPenel.getWidth()-115, 335, 112, 20);
	            }
	        });
	        

		// 开始任务按钮
		SatrtMission = new JButton("开始任务");
		SatrtMission.setBounds(120,210, 100, 25);
		//SatrtMission.setBounds(120, 215, 100, 25);
		SatrtMission.setFont(font);
		SatrtMission.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				SatrtMission.setEnabled(false);
				SatrtMission.setText("执行中....");
				// SatrtMission.setEnabled(false);
				// 查询任务表中的所有任务
				SqlSession session = GetSqlSession.getSession();
				TaskListDao dao = session.getMapper(TaskListDao.class);
				List<TaskList> all = dao.selectnonExecution(user.getId());
				//Test.i=0;
				// 加载到任务列表
				if (all.size() > 0) {
					list=new ArrayList<Integer>();
					for(int i=0;i<table.getRowCount();i++){
						if("未执行".equals(((String)table.getValueAt(i,2)))){
							list.add((Integer) table.getValueAt(i, 0));
						}
					}
					Test.exit=true;
					Test.stall=all;
					//控制循环次数
					Test.ab=true;
					Test.startAuto(all, s3,s2,s1,s6,SatrtMission,list);
					Clock.connect();
				} else {
					SatrtMission.setEnabled(true);
					SatrtMission.setText("开始任务");
					System.out.println("没有任务传入");
				}
				session.close();
				System.out.println("asd");
			}
		});
		leftPenel.add(SatrtMission);

		
		
		
		
		
		// 位置：居中
		Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		jFrame.setLocation((int) (dimension.getWidth() - width) / 2, (int) (dimension.getHeight() - height) / 2);
		
		ImageIcon icon=new ImageIcon("image/01.png");  //xxx代表图片存放路径，2.png图片名称及格式  
		jFrame.setIconImage(icon.getImage());
		System.out.println(icon.getImage());
		
		// 面板可见、不可编辑
		jFrame.setResizable(true);
		jFrame.setVisible(true);
		if(cbOne.isSelected()){
			if(all.size()>0){
				TimerFrame apu=new TimerFrame();
				apu.setIc(new ICallback() {
					
					@Override
					public void postExec() {
						SatrtMission.setEnabled(false);
						SatrtMission.setText("执行中....");
						// SatrtMission.setEnabled(false);
						// 查询任务表中的所有任务
						SqlSession session = GetSqlSession.getSession();
						TaskListDao dao = session.getMapper(TaskListDao.class);
						List<TaskList> all = dao.selectnonExecution(user.getId());
						// 加载到任务列表
						if (all.size() > 0) {
							int browserStatus = 0;
							// 调用浏览器的入口方法
							if (s1.isSelected()) {
								browserStatus = 1;
								System.out.println("谷歌");
							} else if (s2.isSelected()) {
								browserStatus = 2;
								System.out.println("火狐");
							} else if (s3.isSelected()) {
								browserStatus = 3;
								System.out.println("IE");
							}else if(s6.isSelected()){
								Random random = new Random();
								browserStatus = random.nextInt(2)+1;
							}
							List<Integer> list=new ArrayList<Integer>();
							for(int i=0;i<table.getRowCount();i++){
								if("未执行".equals(((String)table.getValueAt(i,2)))){
									list.add((Integer) table.getValueAt(i, 0));
								}
							}
							Test.exit=true;
							Test.startAuto(all,s3,s2,s1,s6,SatrtMission,list);
						}
						
					}
				});
			}
		}
	}
	/*public static void main(String[] args) {
		new Index();
	}
*/

	// 刷新
	public static void refresh(JTable table,int userId) {
		Object[] Names = { "任务ID", "定时时间", "执行状态", "切换IP", "你的网址", "pv","广告选项","点广告页面","删除"};
		// 查询任务表中的所有任务
		SqlSession session = GetSqlSession.getSession();
		TaskListDao dao = session.getMapper(TaskListDao.class);
		List<TaskList> all = dao.selectAll(userId);
		// 加载到任务列表
		if (all.size() > 0) {
			Object[][] o = GetArray.toArray(all,table);
			
			table.setModel(new DefaultTableModel(o, Names));
		        
			table.getColumnModel().getColumn(8).setCellRenderer(new MyButtonRender());
			/*MyButtonEditor editor = new MyButtonEditor(e);
			table.getColumnModel().getColumn(8).setCellEditor(editor);*/
		} else {
			table.setModel(new DefaultTableModel(null, Names));
		}
		GetSqlSession.closeSession(session);
	}
	
	
	

}
